#include <stdio.h>  
#include <string.h>  
char code[105][1005];  
int cntType[105][4];  
  
int main(void) {  
    int n;  
    if (scanf("%d", &n)) ;  
    getchar();  
    for (int i = 0; i < n; i++)  
        if (gets(code[i]));  
    for (int i = 0; i < n; i++) {  
        if (strlen(code[i]) < 6) {  
            printf("Not Safe\n");  
            continue;  
        }  
        for (int j = 0; j < strlen(code[i]); j++) {  
            if (code[i][j] >= '0' && code[i][j] <= '9')  
                cntType[i][0]++;  
            else if (code[i][j] >= 'a' && code[i][j] <= 'z')  
                cntType[i][1]++;  
            else if (code[i][j] >= 'A' && code[i][j] <= 'Z')  
                cntType[i][2]++;  
            else  
                cntType[i][3]++;  
        }  
        int cnt = 0;  
        for (int j = 0; j < 4; j++)  
            if (cntType[i][j] > 0)  
                cnt++;  
        switch (cnt) {  
            case 1:  
                printf("Not Safe\n");  
                break;  
            case 2:  
                printf("Medium Safe\n");  
                break;  
            default:  
                printf("Safe\n");  
        }  
    }  
    return 0;  
}  